package com.xiaoyao.myframeapp.utils.RichScan;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.xiaoyao.myframeapp.FrameApplication;

/**
 * @Author xiaoyao
 * @Email xiao80206040@qq.com
 * @Explain TODO 扫描二维码处理逻辑
 * @Created by Administrator on 2017/10/8 0008 16:31
 */
public class RichScanDisposeLogic {


    /**
     * TODO 扫描二维码处理逻辑
     *
     * @param context
     * @param s
     */
    public static void RichScan_Dispose(Context context, String s, String userId) {
        if (TextUtils.isEmpty(s) || !s.contains("woyouzhijia_type")) {
            RichScan_url(context, s);
            return;
        }

        //TODO 窝友之家扫描二维码处理逻辑
//        ToastUtil.setToast(s);

        RichScanBean richScanBean = FrameApplication.fromJson(s, RichScanBean.class);
        if (richScanBean == null) {
            return;
        }

        int type = Integer.valueOf(richScanBean.getWoyouzhijia_type());
        switch (type) {
            case 0:
                break;
            case 1:
                //TODO 打开个人页面
//                MeCustomization.setSkipDetailsMyUser(
//                        Integer.valueOf(richScanBean.getUrl()),
//                        context);

                break;
            case 3:
                //TODO 打开 跳转 网页 需要参数 用户ID
//                String url = BASE_URL + richScanBean.getUrl();
//                //TODO 拼接商户ID
//                MeCustomization.setSkipDetailsHtml(
//                        url.contains("?") == true ? url + "&" + "buserId=" + userId : url + "?" + "buserId=" + userId,
//                        context);

                break;
        }

    }

    /**
     * 非窝友之家 二维码处理逻辑
     *
     * @param context
     * @param s
     */
    public static void RichScan_url(Context context, String s) {
        //TODO 判断是不是网页
        if (RichScan_url_indexOf(context, s)) {
//            MeCustomization.setSkipDetailsHtml(s, context);
            return;
        }

        //TODO 不是网页直接在网页上面显示二维码数据
        Intent intent = new Intent(context, SecondRestActivity.class);
        intent.putExtra("data", s);//传递二维码数据
        context.startActivity(intent);
    }

    /**
     * 通过判断是不是 http:// ， https:// 或者 www. 开头 来确定是不是网页
     *
     * @param context
     * @param s
     * @return
     */
    public static boolean RichScan_url_indexOf(Context context, String s) {
        String sm = s;
        //TODO 全部转换为小写
        sm = sm.toLowerCase();

        int aaa = sm.indexOf("http://");
        int aaa1 = sm.indexOf("https://");
        int aaa2 = sm.indexOf("www.");

        if (aaa == 0 || aaa1 == 0) {
            return true;
        } else {
            if (aaa2 == 0) {
                return true;
            }
        }
        return false;
    }
}
